type keys =
    //积极
    ""
    | "aiXin"
    | "jianKang"
    | "kauiLe"
    | "ziXin"
    | "chegnshi"
    | "zhihui"
    | "reqing"
    | "fengxian"
    | "ganen"
    | "guoduan"
    | "zilv"
    | "yonggan"
    | "shangliang"
    | "zhenshi"
    | "jiandan"
    | "jianchi"
    | "rennai"
    //消极
    | "jiaolu"
    | "jinzhang"
    | "fennv"
    | "jusang"
    | "beishang"
    | "tongku"
    | "baoyuan"
    | "zize"
    | "huihen"
    | "danyou"
    | "buan"
    | "yumeng"
    | "shangxin"
    | "nanguo"
    | "shiwang"
    | "duoluo"
    | "fanzao"
    ;


export class CWord {
    key: keys = "";
    name: string = "";
}

type SaveType = { keyName: keys, count: number }

export enum WordType {
    //消极
    Negative,
    //积极
    Positive
}

export class SHData {

    private static NegativeWords: Array<CWord> = [
        { key: "jiaolu", name: "焦虑" },
        { key: "jinzhang", name: "紧张" },
        { key: "fennv", name: "愤怒" },
        { key: "jusang", name: "沮丧" },
        { key: "beishang", name: "悲伤" },
        { key: "tongku", name: "痛苦" },
        { key: "baoyuan", name: "抱怨" },
        { key: "zize", name: "自责" },
        { key: "huihen", name: "悔恨" },
        { key: "danyou", name: "担忧" },
        { key: "buan", name: "不安" },
        { key: "yumeng", name: "郁闷" },
        { key: "shangxin", name: "伤心" },
        { key: "nanguo", name: "难过" },
        { key: "shiwang", name: "失望" },
        { key: "duoluo", name: "堕落" },
        { key: "fanzao", name: "烦躁" }
    ];

    private static PositiveWords: Array<CWord> = [
        { key: "aiXin", name: "爱心" },
        { key: "jianKang", name: "健康" },
        { key: "kauiLe", name: "快乐" },
        { key: "ziXin", name: "自信" },
        { key: "chegnshi", name: "诚实" },
        { key: "zhihui", name: "智慧" },
        { key: "reqing", name: "热情" },
        { key: "fengxian", name: "奉献" },
        { key: "ganen", name: "感恩" },
        { key: "guoduan", name: "果断" },
        { key: "zilv", name: "自律" },
        { key: "yonggan", name: "勇敢" },
        { key: "shangliang", name: "善良" },
        { key: "zhenshi", name: "真实" },
        { key: "jiandan", name: "简单" },
        { key: "jianchi", name: "坚持" },
        { key: "rennai", name: "忍耐" },
    ];


    public static GetTiveWord(wordType: WordType): CWord {
        let words: Array<CWord>;
        if (wordType == WordType.Negative) {
            words = this.NegativeWords;
        } else if (wordType == WordType.Positive) {
            words = this.PositiveWords;
        }
        return words[Math.floor(Math.random() * words.length)];
    }

    private static FaileTexts: Array<string> = [
        `唯有消除{N}方能得到解脱`,
        `{N}不除，乐心难安`,
        `即使消除{N}，{P}依然难的`,
        `并不是消除了消除{N}，就可以得到快乐`,
        `也许人生要的是标准答案，而你给的却是真实答案`,
    ];

    public static GetFaileText(negativeWord: CWord, positiveWord: CWord): string {
        let msg = this.FaileTexts[Math.floor(Math.random() * this.FaileTexts.length)];
        msg = msg.replace("{N}", negativeWord.name);
        msg = msg.replace("{P}", positiveWord.name);
        return msg;
    }

    private static SuccessTexts: string[] = [
        "人生充满着期待，梦想连接着未来",
        "君志所向，一往无前，愈挫愈勇，再接再厉",
        "年轻是我们唯一拥有权利去编织梦想的时光",
        "有志者自有千计万计，无志者只感千难万难",
        "没有哪种教育能及得上逆境",
        "只要有信心，人永远不会挫败",
        "成功的法则极为简单，但简单并不代表容易",
        "有高水平的集体，才有高水平的个人",
        "人只要不失去方向，就不会失去自己",
        "不逼自己一把，怎么知道你有多优秀",
        "造物之前，必先造人",
        "成功的人是跟别人学习经验，失败的人只跟自己学习经验",
        "莫找借口失败，只找理由成功",
        "路就在你脚下，只要走，就能到达远方",
    ];

    public static GetSuccessText(): string {
        return this.SuccessTexts[Math.floor(Math.random() * this.SuccessTexts.length)];
    }

    public static SaveWord(word: CWord) {
        let key = word.key;
        let sMsg = this.GetWord(word);
        let count = sMsg === null ? sMsg.count + 1 : 1;
        let saveMsg: SaveType = { keyName: key, count }
        cc.sys.localStorage.setItem(key, JSON.stringify(saveMsg));
    }

    public static GetWord(word: CWord): SaveType {
        let key = word.key;
        let saveMsg = cc.sys.localStorage.getItem(key);
        return JSON.parse(saveMsg) as SaveType;
    }

    public static GetRandomArr(words: CWord[]): CWord[] {
        var array: CWord[] = new Array<CWord>();
        //给原始数组original赋值
        var i: number;
        for (i = 0; i < words.length; i++) {
            array[i] = words[i];
        }
        // 打乱数组顺序(关键)
        array.sort(function () { return 0.5 - Math.random(); });
        // 得到随机数组，按顺序取出，完美解决随机不重复
        return array;
    }


    static readonly MaxCount: number = 9999;


}
